#define _CRT_SECURE_NO_WARNINGS
#include <stdio.h>
#include <stdlib.h>
#include <stdbool.h>
typedef struct {
    int* date;
    int front;
    int rear;
    int size;
    int capacity;
} MyCircularQueue;

MyCircularQueue* myCircularQueueCreate(int k) {
    int* P = (int*)malloc(sizeof(int) * k);
    MyCircularQueue* C = (MyCircularQueue*)malloc(sizeof(MyCircularQueue));
    C->date = P;
    C->front = -1;
    C->size = 0;
    C->rear = -1;
    C->capacity = k;
    return C;
}

bool myCircularQueueEnQueue(MyCircularQueue* obj, int value) {
    if (obj->size < obj->capacity)
    {
        if (obj->rear == obj->front && obj->front == -1)
            obj->rear++;
        obj->date[(++obj->rear) % obj->capacity] = value;
        obj->size++;
        return true;
    }
    else
        return false;
}

bool myCircularQueueDeQueue(MyCircularQueue* obj) {
    if (obj->size > 0)
    {
        obj->date[(++obj->front) % obj->capacity];
        obj->size--;
        return true;
    }
    else
        return false;
}

int myCircularQueueFront(MyCircularQueue* obj) {
    if (obj->size > 0)
    {
        return obj->date[obj->front % obj->capacity];
    }
    else
        return -1;
}

int myCircularQueueRear(MyCircularQueue* obj) {
    if (obj->size > 0)
    {
        return obj->date[obj->rear % obj->capacity];
    }
    else
        return -1;
}

bool myCircularQueueIsEmpty(MyCircularQueue* obj) {
    if (obj->size > 0)
        return false;
    else
        return true;
}

bool myCircularQueueIsFull(MyCircularQueue* obj) {
    if (obj->capacity == obj->size)
        return true;
    else
        return false;
}
// ["MyCircularQueue", "enQueue", "Rear", "Front", "deQueue", "Front", "deQueue", "Front", "enQueue", "enQueue", "enQueue", "enQueue"]
// [[3], [2], [], [], [], [], [], [], [4], [2], [2], [3]]
int main()
{
    MyCircularQueue* obj = myCircularQueueCreate(3);
    myCircularQueueEnQueue(obj,2);
    myCircularQueueRear(obj);
    myCircularQueueFront(obj);
    myCircularQueueDeQueue(obj);
    myCircularQueueFront(obj);
    myCircularQueueDeQueue(obj);
    myCircularQueueFront(obj);
    myCircularQueueEnQueue(obj, 4);
    myCircularQueueEnQueue(obj, 2);
    myCircularQueueEnQueue(obj, 2);
    myCircularQueueEnQueue(obj, 3);
}
